/*
 * Copyright 2011-2021 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0.
 * See `LICENSE` in the project root for license information.
 */

package me.ijleex.mgmt.system.auth.action;

import java.util.Collections;
import javax.servlet.http.HttpServletRequest;

import org.springframework.util.MimeTypeUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import me.ijleex.mgmt.framework.entity.Result;
import me.ijleex.mgmt.system.auth.service.IJwtService;

/**
 * JwtAction.
 *
 * @author liym
 * @since 2020-07-19 16:22 新建
 */
@RequestMapping(value = "/jwt", produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
@RestController
public class JwtAction {

    private final IJwtService jwtService;

    public JwtAction(IJwtService jwtService) {
        this.jwtService = jwtService;
    }

    @RequestMapping("/key-pair")
    public Result keyPair(HttpServletRequest request) {
        return this.jwtService.createKeyPair();
    }

    @RequestMapping("/create")
    public Result create(HttpServletRequest request) {
        long userId = 577054734542819328L;
        String username = "ijliym";

        return this.jwtService.createToken(userId, username, "", Collections.emptyList());
    }

    @RequestMapping("/validate")
    public Result validate(HttpServletRequest request, String token) {
        return this.jwtService.validateToken(token);
    }

}
